//
// Created by yewei on 2023/1/5.
//
#include <bits/stdc++.h>

using namespace std;

int main() {
    freopen("../input.txt", "r", stdin);
    int n;
    cin>>n;
    string s;
    for(int i=0;i<n;i++) s += to_string(i);
    //因为第一个不会进入全排列，所以用do-while
    do{
        int n1 = stoi(s.substr(0,n/2));
        int n2 = stoi(s.substr(n/2+n%2,n/2)); //n的奇偶性影响截取位置
        if(n1%n2==0) cout<<s<<endl;
    }while(next_permutation(s.begin(),s.end()));
}
